package com.larly.controller;


import cn.hutool.core.util.ObjUtil;
import com.larly.annotation.AuthCheck;
import com.larly.common.BaseResponse;
import com.larly.common.IdRequest;
import com.larly.common.PageRequest;
import com.larly.common.ResultUtils;
import com.larly.exception.ErrorCode;
import com.larly.exception.ThrowUtils;
import com.larly.model.domain.NoteLike;
import com.larly.model.vo.NotesLikeVO;
import com.larly.model.vo.UserVO;
import com.larly.service.NoteLikeService;
import com.larly.service.UserFollowService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;


@RestController
@RequestMapping("/user_follow")
public class UserFollowController {

    @Resource
    private UserFollowService userFollowService;

    /**
     * 获取关注列表
     */
    @PostMapping("/getFollowing")
    @AuthCheck
    public BaseResponse<List<UserVO>> getFollowing(@RequestBody PageRequest pageRequest, HttpServletRequest request) {
        ThrowUtils.throwIf(ObjUtil.isNull(pageRequest),ErrorCode.PARAM_ERROR);
        List<UserVO> following = userFollowService.getFollowing(request, pageRequest);
        return ResultUtils.success(following);
    }

    /**
     * 获取粉丝列表
     */
    @PostMapping("/getFollower")
    @AuthCheck
    public BaseResponse<List<UserVO>> getFollower(@RequestBody PageRequest pageRequest, HttpServletRequest request) {
        ThrowUtils.throwIf(ObjUtil.isNull(pageRequest),ErrorCode.PARAM_ERROR);
        List<UserVO> follower = userFollowService.getFollower(request, pageRequest);
        return ResultUtils.success(follower);
    }

}
